package 菜单项;

import java.io.*;
import java.awt.event.*;
import javax.swing.*;

public class HandleListener implements ActionListener {
	JTextArea inputText, showText;
	JTextField textField;

	WindowDocument win;

	public void setInputText(JTextArea text) {
		inputText = text;
	}

	public void setShowText(JTextArea text) {
		showText = text;
	}

	public void wind(WindowDocument wind) {
		win = wind;
	}

	public void actionPerformed(ActionEvent e) {
		String str = e.getActionCommand();
		if (str.equals("copy"))
			showText.copy();
		else if (str.equals("cut"))
			showText.cut();
		else if (str.equals("paste"))
			inputText.paste();
		else if (str.equals("preservation")) {
			File file = new File("a.txt");

			try {
				Writer out = new FileWriter(file);
				BufferedWriter bufferedWriter = new BufferedWriter(out);
				String str1 = showText.getText();
				String str2[] = str1.split(",");
				for (int i = 0; i < str2.length; i++) {
					bufferedWriter.write(str2[i]);
					bufferedWriter.newLine();
				}

				bufferedWriter.close();
				out.close();
			} catch (IOException e1) {
				e1.printStackTrace();
				JOptionPane.showMessageDialog(null, "保存失败");
			}
			JOptionPane.showMessageDialog(null, "保存成功");
		} else if (str.equals("opan")) {
			File file = new File("a.txt");

			try {
				Reader in = new FileReader(file);
				BufferedReader bufferedReader = new BufferedReader(in);
				String str3 = null;
				while ((str3 = bufferedReader.readLine()) != null) {

					showText.append(str3 + ",");

				}

			} catch (IOException e1) {
				e1.printStackTrace();
				JOptionPane.showMessageDialog(null, "打开失败");
			}
			JOptionPane.showMessageDialog(null, "打开成功");
		}
		if (str.equals("replace")) {

			Find f = new Find();
			f.setShowText(showText);
			f.setBounds(100, 100, 200, 200);

		}

	}

}
